package com.zjw.zy.coreui.fragment.access

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.viewModels
import com.zjw.zy.R
import com.zjw.zy.base.BaseFragment
import com.zjw.zy.bean.BindLoveInfo
import com.zjw.zy.bean.User
import com.zjw.zy.manager.PageManager
import com.zjw.zy.utils.AppUtils
import com.zjw.zy.utils.TimeUtils
import com.zjw.zy.viewmodel.AccessViewModel
import java.util.*

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/12/7 14:23
 * @description：
 */
class AccessResultFragment : BaseFragment() {

    private val mAccessViewModel: AccessViewModel by viewModels({ requireParentFragment() })


    private val selfName: TextView by lazy { findViewById(R.id.access_result_self_name) }
    private val loverName: TextView by lazy { findViewById(R.id.access_result_lover_name) }
    private val date: TextView by lazy { findViewById(R.id.access_result_date) }
    private val enter: Button by lazy { findViewById(R.id.access_result_enter) }
    override fun onPageEnter() {

    }

    override fun onViewRestore(savedInstanceState: Bundle?) {

    }

    override fun onSubscribe() {
        mAccessViewModel.getBindInfo().observe(this) {
            date.text = TimeUtils.formatDate(Date(it.id), "yyyy-MM-dd")
            AppUtils.getSelf()?.apply { selfName.text = this.name }
            AppUtils.getLove()?.apply { loverName.text = this.name }
        }

    }

    override fun onBindViewListener() {
        enter.setOnClickListener {
            PageManager.goMain()
        }
    }

    override fun onBindViewValue() {
        AppUtils.getSelf()?.apply {
            selfName.text = this.name
        }
        AppUtils.getLove()?.apply {
            this.getInfo(
                User.BIND_INFO_KEY,
                BindLoveInfo::class.java
            )?.id?.let { t ->
                date.text = TimeUtils.formatDate(Date(t), "yyyy-MM-dd")
            }
            loverName.text = this.name
        }
    }

    override fun onFindView(rootView: View?) {

    }

    override fun onLayoutId(): Int {
        return R.layout.fragment_result_access
    }

    override fun onPageExit() {

    }
}